In [43]:
#import all required libraires
import pandas as pd
import numpy as np
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', 100)
pd.set_option('display.width',1000)
import matplotlib.cm as cm            # Matplotlib and associated plotting modules
import matplotlib.colors as colors
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans  # import k-means from clustering stage
from sklearn.metrics import silhouette_score
import folium                        # map rendering library
import json # library to handle JSON files
from pandas.io.json import json_normalize
from geopy.geocoders import Nominatim
import requests # library to handle requests
import webbrowser
import pgeocode
In [44]:
#getting cordinates for Mumbai
address = 'Mumbai'
geolocator = Nominatim(user_agent="ny_explorer")
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
print('The geograpical coordinate of Mumbai are {}, {}.'.format(latitude, longitude))
The geograpical coordinate of Mumbai are 19.0759899, 72.8773928.
In [45]:
#read data from the webpage
url = 'https://en.wikipedia.org/wiki/List_of_neighbourhoods_in_Mumbai'
df1 = pd.read_html(url)
type(df1)
Out[45]:
list
In [46]:
df1
Out[46]:
[                                               0                                1          2          3
 0                                           Area                         Location   Latitude  Longitude
 1                                         Amboli          Andheri,Western Suburbs    19.1293    72.8434
 2                               Chakala, Andheri                  Western Suburbs  19.111388  72.860833
 3                                     D.N. Nagar          Andheri,Western Suburbs  19.124085  72.831373
 4                                 Four Bungalows          Andheri,Western Suburbs  19.124714   72.82721
 5                                    Lokhandwala          Andheri,Western Suburbs  19.130815   72.82927
 6                                          Marol          Andheri,Western Suburbs  19.119219  72.882743
 7                                          Sahar          Andheri,Western Suburbs  19.098889  72.867222
 8                                Seven Bungalows          Andheri,Western Suburbs  19.129052  72.817018
 9                                        Versova          Andheri,Western Suburbs      19.12      72.82
 10                                     Mira Road   Mira-Bhayandar,Western Suburbs  19.284167  72.871111
 11                                     Bhayandar   Mira-Bhayandar,Western Suburbs      19.29      72.85
 12                                         Uttan   Mira-Bhayandar,Western Suburbs      19.28     72.785
 13                           Bandstand Promenade           Bandra,Western Suburbs  19.042718  72.819132
 14                                      Kherwadi           Bandra,Western Suburbs    19.0553    72.8314
 15                                     Pali Hill           Bandra,Western Suburbs     19.068     72.826
 16                                   I.C. Colony  Borivali (West),Western Suburbs  19.247039   72.84983
 17                                         Gorai  Borivali (West),Western Suburbs  19.250057  72.782021
 18                                        Dahisa                  Western Suburbs  19.250069  72.859347
 19                             Aarey Milk Colony         Goregaon,Western Suburbs  19.148493  72.881756
 20                                  Bangur Nagar         Goregaon,Western Suburbs  19.167362  72.832252
 21                               Jogeshwari West                  Western Suburbs      19.12      72.85
 22                                          Juhu                  Western Suburbs       19.1      72.83
 23                                       Charkop   Kandivali West,Western Suburbs  19.216182  72.830575
 24                                        Poisar   Kandivali West,Western Suburbs  19.204511  72.837639
 25                                 Mahavir Nagar   Kandivali West,Western Suburbs  19.211319  72.842737
 26                                Thakur village   Kandivali East,Western Suburbs  19.210206   72.87298
 27                                     Pali Naka             Khar,Western Suburbs  19.062742  72.829396
 28                                    Khar Danda             Khar,Western Suburbs  19.068598  72.840042
 29                                      Dindoshi            Malad,Western Suburbs  19.176382  72.864891
 30                                  Sunder Nagar            Malad,Western Suburbs     19.175     72.842
 31                                        Kalina       Sanctacruz,Western Suburbs  19.081667  72.841389
 32                                       Naigaon            Vasai,Western Suburbs  19.351467  72.846343
 33                                    Nalasopara            Vasai,Western Suburbs    19.4154    72.8613
 34                                         Virar                  Western Suburbs      19.47       72.8
 35                                          Irla       Vile Parle,Western Suburbs  19.108056  72.838056
 36                                    Vile Parle                  Western Suburbs       19.1      72.83
 37                                       Bhandup                  Eastern Suburbs      19.14      72.93
 38                                   Amrut Nagar        Ghatkopar,Eastern Suburbs  19.102077  72.912835
 39                                        Asalfa        Ghatkopar,Eastern Suburbs     19.091     72.901
 40                                    Pant Nagar        Ghatkopar,Eastern Suburbs      19.08      72.91
 41                                    Kanjurmarg                  Eastern Suburbs      19.13      72.94
 42                                   Nehru Nagar            Kurla,Eastern Suburbs  15.451686  74.971977
 43                                         Nahur           Mulund,Eastern Suburbs     19.157     72.941
 44                                    Chandivali            Powai,Eastern Suburbs      19.11       72.9
 45                           Hiranandani Gardens            Powai,Eastern Suburbs  19.118986  72.911767
 46  Indian Institute of Technology Bombay campus            Powai,Eastern Suburbs  19.133636  72.915358
 47                                    Vidyavihar                  Eastern Suburbs      19.08     72.896
 48                                      Vikhroli                  Eastern Suburbs      19.11      72.94
 49                                       Chembur                  Harbour Suburbs     19.051     72.894
 50                                        Deonar          Govandi,Harbour Suburbs      19.05      72.89
 51                                      Mankhurd                  Harbour Suburbs      19.05      72.93
 52                                         Mahul          Trombay,Harbour Suburbs         19  72.883333
 53                                      Agripada                     South Mumbai    18.9777    72.8273
 54                                Altamount Road                     South Mumbai    18.9681    72.8095
 55                                    Bhuleshwar                     South Mumbai      18.95      72.83
 56                                  Breach Candy                     South Mumbai     18.967     72.805
 57                               Carmichael Road                     South Mumbai    18.9722    72.8113
 58                                         Cavel                     South Mumbai    18.9474    72.8272
 59                                    Churchgate                     South Mumbai      18.93      72.82
 60                                  Cotton Green                     South Mumbai  18.986209  72.844076
 61                                  Cuffe Parade                     South Mumbai      18.91      72.81
 62                                  Cumbala Hill                     South Mumbai  18.965833  72.805833
 63                                   Currey Road                     South Mumbai     18.994     72.833
 64                                    Dhobitalao                     South Mumbai    18.9433    72.8286
 65                                        Dongri                     South Mumbai  19.283333  72.783333
 66                                    Kala Ghoda                     South Mumbai    18.9307    72.8331
 67                                  Kemps Corner                     South Mumbai    18.9629    72.8054
 68                                   Lower Parel                     South Mumbai  18.995278      72.83
 69                                     Mahalaxmi                     South Mumbai  18.983333       72.8
 70                                         Mahim                     South Mumbai     19.035      72.84
 71                                  Malabar Hill                     South Mumbai      18.95     72.795
 72                                  Marine Drive                     South Mumbai     18.944     72.823
 73                                  Marine Lines                     South Mumbai    18.9447    72.8244
 74                                Mumbai Central                     South Mumbai    18.9697    72.8194
 75                                 Nariman Point                     South Mumbai     18.926     72.823
 76                                    Prabhadevi                     South Mumbai    19.0166    72.8295
 77                                          Sion                     South Mumbai      19.04      72.86
 78                                    Walkeshwar                     South Mumbai  18.947596  72.795957
 79                                         Worli                     South Mumbai         19     72.815
 80                                 C.G.S. colony          Antop Hill,South Mumbai  19.016378  72.856629
 81                                   Dagdi Chawl             Byculla,South Mumbai  18.977129  72.829131
 82                                    Navy Nagar              Colaba,South Mumbai    18.9012    72.8101
 83                                  Hindu colony               Dadar,South Mumbai  19.020841  19.020841
 84                                Ballard Estate                Fort,South Mumbai      18.95      72.84
 85                                  Chira Bazaar           Kalbadevi,South Mumbai   18.94814  72.825462
 86                                    Fanas Wadi           Kalbadevi,South Mumbai  18.951811  72.825309
 87                                   Chor Bazaar         Kamathipura,South Mumbai  18.960321  72.827176
 88                                       Matunga                     South Mumbai   19.01798  72.844763
 89                                         Parel                     South Mumbai      18.99      72.84
 90                                  Gowalia Tank              Tardeo,South Mumbai   18.96245  72.809703
 91                                   Dava Bazaar                     South Mumbai  18.946882  72.831362
 92                                       Dharavi                           Mumbai  19.040208   72.85085
 93                                         Thane                           Mumbai       19.2      72.97]
In [47]:
#to convert data into dataframe, first need to convert into nummpy array,then tranpose the list
df2_T0 = np.array(df1[0][0]).T.tolist()
df2_T1 = np.array(df1[0][1]).T.tolist()
df2_T2 = np.array(df1[0][2]).T.tolist()
df2_T3 = np.array(df1[0][3]).T.tolist()
#noq combine the list and convert into a dataframe
df3=pd.DataFrame(list(zip(df2_T0, df2_T1,df2_T2,df2_T3)),
             columns=['Area','Location','Latitude','Longitude'])
type(df3)
Out[47]:
pandas.core.frame.DataFrame
In [48]:
MumbaiLatLan=df3.drop(df3.index[0])
MumbaiLatLan
Out[48]:
Area Location Latitude Longitude
1 Amboli Andheri,Western Suburbs 19.1293 72.8434
2 Chakala, Andheri Western Suburbs 19.111388 72.860833
3 D.N. Nagar Andheri,Western Suburbs 19.124085 72.831373
4 Four Bungalows Andheri,Western Suburbs 19.124714 72.82721
5 Lokhandwala Andheri,Western Suburbs 19.130815 72.82927
6 Marol Andheri,Western Suburbs 19.119219 72.882743
7 Sahar Andheri,Western Suburbs 19.098889 72.867222
8 Seven Bungalows Andheri,Western Suburbs 19.129052 72.817018
9 Versova Andheri,Western Suburbs 19.12 72.82
10 Mira Road Mira-Bhayandar,Western Suburbs 19.284167 72.871111
11 Bhayandar Mira-Bhayandar,Western Suburbs 19.29 72.85
12 Uttan Mira-Bhayandar,Western Suburbs 19.28 72.785
13 Bandstand Promenade Bandra,Western Suburbs 19.042718 72.819132
14 Kherwadi Bandra,Western Suburbs 19.0553 72.8314
15 Pali Hill Bandra,Western Suburbs 19.068 72.826
16 I.C. Colony Borivali (West),Western Suburbs 19.247039 72.84983
17 Gorai Borivali (West),Western Suburbs 19.250057 72.782021
18 Dahisa Western Suburbs 19.250069 72.859347
19 Aarey Milk Colony Goregaon,Western Suburbs 19.148493 72.881756
20 Bangur Nagar Goregaon,Western Suburbs 19.167362 72.832252
21 Jogeshwari West Western Suburbs 19.12 72.85
22 Juhu Western Suburbs 19.1 72.83
23 Charkop Kandivali West,Western Suburbs 19.216182 72.830575
24 Poisar Kandivali West,Western Suburbs 19.204511 72.837639
25 Mahavir Nagar Kandivali West,Western Suburbs 19.211319 72.842737
26 Thakur village Kandivali East,Western Suburbs 19.210206 72.87298
27 Pali Naka Khar,Western Suburbs 19.062742 72.829396
28 Khar Danda Khar,Western Suburbs 19.068598 72.840042
29 Dindoshi Malad,Western Suburbs 19.176382 72.864891
30 Sunder Nagar Malad,Western Suburbs 19.175 72.842
31 Kalina Sanctacruz,Western Suburbs 19.081667 72.841389
32 Naigaon Vasai,Western Suburbs 19.351467 72.846343
33 Nalasopara Vasai,Western Suburbs 19.4154 72.8613
34 Virar Western Suburbs 19.47 72.8
35 Irla Vile Parle,Western Suburbs 19.108056 72.838056
36 Vile Parle Western Suburbs 19.1 72.83
37 Bhandup Eastern Suburbs 19.14 72.93
38 Amrut Nagar Ghatkopar,Eastern Suburbs 19.102077 72.912835
39 Asalfa Ghatkopar,Eastern Suburbs 19.091 72.901
40 Pant Nagar Ghatkopar,Eastern Suburbs 19.08 72.91
41 Kanjurmarg Eastern Suburbs 19.13 72.94
42 Nehru Nagar Kurla,Eastern Suburbs 15.451686 74.971977
43 Nahur Mulund,Eastern Suburbs 19.157 72.941
44 Chandivali Powai,Eastern Suburbs 19.11 72.9
45 Hiranandani Gardens Powai,Eastern Suburbs 19.118986 72.911767
46 Indian Institute of Technology Bombay campus Powai,Eastern Suburbs 19.133636 72.915358
47 Vidyavihar Eastern Suburbs 19.08 72.896
48 Vikhroli Eastern Suburbs 19.11 72.94
49 Chembur Harbour Suburbs 19.051 72.894
50 Deonar Govandi,Harbour Suburbs 19.05 72.89
51 Mankhurd Harbour Suburbs 19.05 72.93
52 Mahul Trombay,Harbour Suburbs 19 72.883333
53 Agripada South Mumbai 18.9777 72.8273
54 Altamount Road South Mumbai 18.9681 72.8095
55 Bhuleshwar South Mumbai 18.95 72.83
56 Breach Candy South Mumbai 18.967 72.805
57 Carmichael Road South Mumbai 18.9722 72.8113
58 Cavel South Mumbai 18.9474 72.8272
59 Churchgate South Mumbai 18.93 72.82
60 Cotton Green South Mumbai 18.986209 72.844076
61 Cuffe Parade South Mumbai 18.91 72.81
62 Cumbala Hill South Mumbai 18.965833 72.805833
63 Currey Road South Mumbai 18.994 72.833
64 Dhobitalao South Mumbai 18.9433 72.8286
65 Dongri South Mumbai 19.283333 72.783333
66 Kala Ghoda South Mumbai 18.9307 72.8331
67 Kemps Corner South Mumbai 18.9629 72.8054
68 Lower Parel South Mumbai 18.995278 72.83
69 Mahalaxmi South Mumbai 18.983333 72.8
70 Mahim South Mumbai 19.035 72.84
71 Malabar Hill South Mumbai 18.95 72.795
72 Marine Drive South Mumbai 18.944 72.823
73 Marine Lines South Mumbai 18.9447 72.8244
74 Mumbai Central South Mumbai 18.9697 72.8194
75 Nariman Point South Mumbai 18.926 72.823
76 Prabhadevi South Mumbai 19.0166 72.8295
77 Sion South Mumbai 19.04 72.86
78 Walkeshwar South Mumbai 18.947596 72.795957
79 Worli South Mumbai 19 72.815
80 C.G.S. colony Antop Hill,South Mumbai 19.016378 72.856629
81 Dagdi Chawl Byculla,South Mumbai 18.977129 72.829131
82 Navy Nagar Colaba,South Mumbai 18.9012 72.8101
83 Hindu colony Dadar,South Mumbai 19.020841 19.020841
84 Ballard Estate Fort,South Mumbai 18.95 72.84
85 Chira Bazaar Kalbadevi,South Mumbai 18.94814 72.825462
86 Fanas Wadi Kalbadevi,South Mumbai 18.951811 72.825309
87 Chor Bazaar Kamathipura,South Mumbai 18.960321 72.827176
88 Matunga South Mumbai 19.01798 72.844763
89 Parel South Mumbai 18.99 72.84
90 Gowalia Tank Tardeo,South Mumbai 18.96245 72.809703
91 Dava Bazaar South Mumbai 18.946882 72.831362
92 Dharavi Mumbai 19.040208 72.85085
93 Thane Mumbai 19.2 72.97
In [49]:
# create map of Mumbai using latitude and longitude values
map_Mumbai = folium.Map(location=[latitude, longitude], zoom_start=11)
# add markers to map

map_Mumbai
Out[49]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [50]:
# create map of Mumbai using latitude and longitude values
map_mumbai = folium.Map(location=[latitude, longitude], zoom_start=11)
# add markers to map
for lat, lng, label in zip(MumbaiLatLan['Latitude'], MumbaiLatLan['Longitude'],MumbaiLatLan['Area']):
    label = folium.Popup(label, parse_html=False)
    folium.CircleMarker(
        [lat, lng],
        radius=5,
        popup=label,
        color='blue',
        fill=True,
        fill_color='#3186cc',
        fill_opacity=1,
        parse_html=False).add_to(map_mumbai)  
map_mumbai
Out[50]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [51]:
#Define Foursquare Credentials and Version
#@hidden_cell
CLIENT_ID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # your Foursquare ID
CLIENT_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # your Foursquare Secret
VERSION = '20180605' # Foursquare API version
LIMIT = 100 # A default Foursquare API limit value
In [52]:
#Explore Neighborhoods in Mumbai
def getNearbyVenues(names, latitudes, longitudes, radius=2500):
    
    venues_list=[]
    for name, lat, lng in zip(names, latitudes, longitudes):
        print(name)
            
        # create the API request URL
        url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&limit={}'.format(
            CLIENT_ID, 
            CLIENT_SECRET, 
            VERSION, 
            lat, 
            lng, 
            radius, 
            LIMIT)
            
        # make the GET request
        results = requests.get(url).json()["response"]['groups'][0]['items']
        
        # return only relevant information for each nearby venue
        venues_list.append([(
            name, 
            lat, 
            lng, 
            v['venue']['name'], 
            v['venue']['location']['lat'], 
            v['venue']['location']['lng'],  
            v['venue']['categories'][0]['name']) for v in results])

    nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])
    nearby_venues.columns = ['Neighborhood', 
                  'Neighborhood Latitude', 
                  'Neighborhood Longitude', 
                  'Venue', 
                  'Venue Latitude', 
                  'Venue Longitude', 
                  'Venue Category']
    
    return(nearby_venues)
In [53]:
#Now write the code to run the above function on each neighborhood and create a new dataframe called Mumbai_venues.
# type your answer here
Mumbai_venues = getNearbyVenues(names=MumbaiLatLan['Area'],
                                   latitudes=MumbaiLatLan['Latitude'],
                                   longitudes=MumbaiLatLan['Longitude']
                                  )

print(Mumbai_venues.shape)
Mumbai_venues.head(5)
Amboli
Chakala, Andheri
D.N. Nagar
Four Bungalows
Lokhandwala
Marol
Sahar
Seven Bungalows
Versova
Mira Road
Bhayandar
Uttan
Bandstand Promenade
Kherwadi
Pali Hill
I.C. Colony
Gorai
Dahisa
Aarey Milk Colony
Bangur Nagar
Jogeshwari West
Juhu
Charkop
Poisar
Mahavir Nagar
Thakur village
Pali Naka
Khar Danda
Dindoshi
Sunder Nagar
Kalina
Naigaon
Nalasopara
Virar
Irla
Vile Parle
Bhandup
Amrut Nagar
Asalfa
Pant Nagar
Kanjurmarg
Nehru Nagar
Nahur
Chandivali
Hiranandani Gardens
Indian Institute of Technology Bombay campus
Vidyavihar
Vikhroli
Chembur
Deonar
Mankhurd
Mahul
Agripada
Altamount Road
Bhuleshwar
Breach Candy
Carmichael Road
Cavel
Churchgate
Cotton Green
Cuffe Parade
Cumbala Hill
Currey Road
Dhobitalao
Dongri
Kala Ghoda
Kemps Corner
Lower Parel
Mahalaxmi
Mahim
Malabar Hill
Marine Drive
Marine Lines
Mumbai Central
Nariman Point
Prabhadevi
Sion
Walkeshwar
Worli
C.G.S. colony
Dagdi Chawl
Navy Nagar
Hindu colony
Ballard Estate
Chira Bazaar
Fanas Wadi
Chor Bazaar
Matunga
Parel
Gowalia Tank
Dava Bazaar
Dharavi
Thane
(7371, 7)
Out[53]:
Neighborhood Neighborhood Latitude Neighborhood Longitude Venue Venue Latitude Venue Longitude Venue Category
0 Amboli 19.1293 72.8434 Merwans Cake shop 19.119300 72.845418 Bakery
1 Amboli 19.1293 72.8434 Jaffer Bhai's Delhi Darbar 19.137714 72.845909 Mughlai Restaurant
2 Amboli 19.1293 72.8434 Hard Rock Cafe Andheri 19.135995 72.835335 American Restaurant
3 Amboli 19.1293 72.8434 Shawarma Factory 19.124591 72.840398 Falafel Restaurant
4 Amboli 19.1293 72.8434 Joey's Pizza 19.126762 72.830001 Pizza Place
In [54]:
#Let's check how many venues were returned for each neighborhood
Mumbai_venues.groupby('Neighborhood').count()
Out[54]:
Neighborhood Latitude Neighborhood Longitude Venue Venue Latitude Venue Longitude Venue Category
Neighborhood
Aarey Milk Colony 25 25 25 25 25 25
Agripada 100 100 100 100 100 100
Altamount Road 100 100 100 100 100 100
Amboli 100 100 100 100 100 100
Amrut Nagar 100 100 100 100 100 100
Asalfa 100 100 100 100 100 100
Ballard Estate 100 100 100 100 100 100
Bandstand Promenade 100 100 100 100 100 100
Bangur Nagar 100 100 100 100 100 100
Bhandup 41 41 41 41 41 41
Bhayandar 28 28 28 28 28 28
Bhuleshwar 100 100 100 100 100 100
Breach Candy 100 100 100 100 100 100
C.G.S. colony 92 92 92 92 92 92
Carmichael Road 100 100 100 100 100 100
Cavel 100 100 100 100 100 100
Chakala, Andheri 100 100 100 100 100 100
Chandivali 100 100 100 100 100 100
Charkop 92 92 92 92 92 92
Chembur 82 82 82 82 82 82
Chira Bazaar 100 100 100 100 100 100
Chor Bazaar 56 56 56 56 56 56
Churchgate 100 100 100 100 100 100
Cotton Green 100 100 100 100 100 100
Cuffe Parade 65 65 65 65 65 65
Cumbala Hill 100 100 100 100 100 100
Currey Road 100 100 100 100 100 100
D.N. Nagar 100 100 100 100 100 100
Dagdi Chawl 100 100 100 100 100 100
Dahisa 75 75 75 75 75 75
Dava Bazaar 100 100 100 100 100 100
Deonar 86 86 86 86 86 86
Dharavi 100 100 100 100 100 100
Dhobitalao 100 100 100 100 100 100
Dindoshi 72 72 72 72 72 72
Dongri 9 9 9 9 9 9
Fanas Wadi 100 100 100 100 100 100
Four Bungalows 100 100 100 100 100 100
Gorai 5 5 5 5 5 5
Gowalia Tank 100 100 100 100 100 100
Hiranandani Gardens 100 100 100 100 100 100
I.C. Colony 88 88 88 88 88 88
Indian Institute of Technology Bombay campus 91 91 91 91 91 91
Irla 100 100 100 100 100 100
Jogeshwari West 100 100 100 100 100 100
Juhu 69 69 69 69 69 69
Kala Ghoda 100 100 100 100 100 100
Kalina 100 100 100 100 100 100
Kanjurmarg 28 28 28 28 28 28
Kemps Corner 99 99 99 99 99 99
Khar Danda 100 100 100 100 100 100
Kherwadi 57 57 57 57 57 57
Lokhandwala 100 100 100 100 100 100
Lower Parel 100 100 100 100 100 100
Mahalaxmi 65 65 65 65 65 65
Mahavir Nagar 100 100 100 100 100 100
Mahim 100 100 100 100 100 100
Mahul 4 4 4 4 4 4
Malabar Hill 61 61 61 61 61 61
Mankhurd 13 13 13 13 13 13
Marine Drive 100 100 100 100 100 100
Marine Lines 100 100 100 100 100 100
Marol 100 100 100 100 100 100
Matunga 100 100 100 100 100 100
Mira Road 37 37 37 37 37 37
Mumbai Central 100 100 100 100 100 100
Nahur 71 71 71 71 71 71
Naigaon 4 4 4 4 4 4
Nalasopara 7 7 7 7 7 7
Nariman Point 100 100 100 100 100 100
Navy Nagar 23 23 23 23 23 23
Nehru Nagar 6 6 6 6 6 6
Pali Hill 100 100 100 100 100 100
Pali Naka 65 65 65 65 65 65
Pant Nagar 100 100 100 100 100 100
Parel 100 100 100 100 100 100
Poisar 100 100 100 100 100 100
Prabhadevi 100 100 100 100 100 100
Sahar 100 100 100 100 100 100
Seven Bungalows 100 100 100 100 100 100
Sion 100 100 100 100 100 100
Sunder Nagar 100 100 100 100 100 100
Thakur village 75 75 75 75 75 75
Thane 100 100 100 100 100 100
Uttan 8 8 8 8 8 8
Versova 100 100 100 100 100 100
Vidyavihar 100 100 100 100 100 100
Vikhroli 24 24 24 24 24 24
Vile Parle 69 69 69 69 69 69
Virar 14 14 14 14 14 14
Walkeshwar 65 65 65 65 65 65
Worli 100 100 100 100 100 100
In [55]:
#Let's find out how many unique categories can be curated from all the returned venues
print('There are {} uniques categories.'.format(len(Mumbai_venues['Venue Category'].unique())))
There are 210 uniques categories.
In [56]:
# Now just keeing Shopping malls & Theatre for the analysis
Mumbai_venues_2=Mumbai_venues[(Mumbai_venues['Venue Category']=='Shopping Mall') | (Mumbai_venues['Venue Category']=='Movie Theater') 
                           | (Mumbai_venues['Venue Category']=='Theater') | (Mumbai_venues['Venue Category']=='Indie Movie Theater')]

Mumbai_venues_2['Venue Category'] = Mumbai_venues_2['Venue Category'].replace(['Movie Theater','Indie Movie Theater'],'Theater')

Mumbai_venues_2
C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  """
Out[56]:
Neighborhood Neighborhood Latitude Neighborhood Longitude Venue Venue Latitude Venue Longitude Venue Category
28 Amboli 19.1293 72.8434 PVR ICON 19.141531 72.830331 Theater
229 D.N. Nagar 19.124085 72.831373 Prithvi Theatre 19.106157 72.825810 Theater
255 D.N. Nagar 19.124085 72.831373 PVR ICON 19.141531 72.830331 Theater
330 Four Bungalows 19.124714 72.82721 Prithvi Theatre 19.106157 72.825810 Theater
352 Four Bungalows 19.124714 72.82721 PVR ICON 19.141531 72.830331 Theater
423 Lokhandwala 19.130815 72.82927 PVR ICON 19.141531 72.830331 Theater
749 Seven Bungalows 19.129052 72.817018 PVR ICON 19.141531 72.830331 Theater
812 Versova 19.12 72.82 Prithvi Theatre 19.106157 72.825810 Theater
932 Mira Road 19.284167 72.871111 Inox Cinemas - Thakur Mall - Dahisar 19.263130 72.874483 Theater
1046 Bandstand Promenade 19.042718 72.819132 Le Rêve (Globus Cinema) 19.056014 72.833951 Theater
1257 I.C. Colony 19.247039 72.84983 Sona GOLD 19.234830 72.865032 Theater
1290 I.C. Colony 19.247039 72.84983 Prabodhankar Thackeray Natya Mandir 19.233363 72.854462 Theater
1336 Dahisa 19.250069 72.859347 Sona GOLD 19.234830 72.865032 Theater
1378 Dahisa 19.250069 72.859347 Prabodhankar Thackeray Natya Mandir 19.233363 72.854462 Theater
1395 Dahisa 19.250069 72.859347 Inox Cinemas - Thakur Mall - Dahisar 19.263130 72.874483 Theater
1427 Bangur Nagar 19.167362 72.832252 Inorbit Mall 19.173065 72.835755 Shopping Mall
1437 Bangur Nagar 19.167362 72.832252 Infiniti Mall 19.184692 72.834914 Shopping Mall
1629 Juhu 19.1 72.83 Prithvi Theatre 19.106157 72.825810 Theater
1771 Charkop 19.216182 72.830575 INOX Raghuleela 19.213397 72.849115 Theater
1803 Poisar 19.204511 72.837639 Infiniti Mall 19.184692 72.834914 Shopping Mall
1862 Poisar 19.204511 72.837639 Growel's 101 19.202952 72.860453 Shopping Mall
1930 Mahavir Nagar 19.211319 72.842737 Growel's 101 19.202952 72.860453 Shopping Mall
1997 Thakur village 19.210206 72.87298 Inox 19.212185 72.871501 Theater
2004 Thakur village 19.210206 72.87298 Growel's 101 19.202952 72.860453 Shopping Mall
2032 Thakur village 19.210206 72.87298 Metro Mall 19.218714 72.866107 Shopping Mall
2049 Thakur village 19.210206 72.87298 Centrium Mall 19.196567 72.871714 Shopping Mall
2229 Dindoshi 19.176382 72.864891 Oberoi Mall 19.174061 72.860412 Shopping Mall
2300 Sunder Nagar 19.175 72.842 Infiniti Mall 19.184692 72.834914 Shopping Mall
2308 Sunder Nagar 19.175 72.842 Inorbit Mall 19.173065 72.835755 Shopping Mall
2332 Sunder Nagar 19.175 72.842 Oberoi Mall 19.174061 72.860412 Shopping Mall
2527 Irla 19.108056 72.838056 Prithvi Theatre 19.106157 72.825810 Theater
2627 Vile Parle 19.1 72.83 Prithvi Theatre 19.106157 72.825810 Theater
2708 Bhandup 19.14 72.93 Magnet Mall 19.141503 72.931681 Shopping Mall
2733 Amrut Nagar 19.102077 72.912835 R City Mall 19.099320 72.916714 Shopping Mall
2826 Amrut Nagar 19.102077 72.912835 Neptune Magnet Mall 19.113237 72.916708 Shopping Mall
2833 Asalfa 19.091 72.901 PVR Cinemas 19.086643 72.889839 Theater
2842 Asalfa 19.091 72.901 Phoenix Marketcity 19.085914 72.888692 Shopping Mall
2846 Asalfa 19.091 72.901 R City Mall 19.099320 72.916714 Shopping Mall
2947 Pant Nagar 19.08 72.91 PVR Cinemas 19.086643 72.889839 Theater
2951 Pant Nagar 19.08 72.91 R City Mall 19.099320 72.916714 Shopping Mall
2961 Pant Nagar 19.08 72.91 Phoenix Marketcity 19.085914 72.888692 Shopping Mall
3049 Kanjurmarg 19.13 72.94 Magnet Mall 19.141503 72.931681 Shopping Mall
3083 Nahur 19.157 72.941 R mall, Mulund west 19.175375 72.950506 Shopping Mall
3096 Nahur 19.157 72.941 Mahakavi Kalidas Natya Mandir 19.173408 72.949012 Theater
3124 Nahur 19.157 72.941 Magnet Mall 19.141503 72.931681 Shopping Mall
3162 Chandivali 19.11 72.9 R City Mall 19.099320 72.916714 Shopping Mall
3278 Hiranandani Gardens 19.118986 72.911767 R City Mall 19.099320 72.916714 Shopping Mall
3410 Indian Institute of Technology Bombay campus 19.133636 72.915358 Magnet Mall 19.141503 72.931681 Shopping Mall
3413 Indian Institute of Technology Bombay campus 19.133636 72.915358 Huma Mall 19.134935 72.927979 Shopping Mall
3428 Vidyavihar 19.08 72.896 PVR Cinemas 19.086643 72.889839 Theater
3434 Vidyavihar 19.08 72.896 Phoenix Marketcity 19.085914 72.888692 Shopping Mall
3514 Vidyavihar 19.08 72.896 Cinemax 19.074561 72.906534 Theater
3537 Vikhroli 19.11 72.94 Neptune Magnet Mall 19.113237 72.916708 Shopping Mall
3595 Chembur 19.051 72.894 Movie Time 19.045790 72.903118 Theater
3677 Deonar 19.05 72.89 Movie Time 19.045790 72.903118 Theater
3747 Agripada 18.9777 72.8273 High Street Phoenix 18.994967 72.825032 Shopping Mall
3752 Agripada 18.9777 72.8273 Palladium 18.994317 72.824398 Shopping Mall
3833 Agripada 18.9777 72.8273 Sophia Bhabha Hall 18.969819 72.807082 Theater
3849 Altamount Road 18.9681 72.8095 Sophia Bhabha Hall 18.969819 72.807082 Theater
4051 Breach Candy 18.967 72.805 Sophia Bhabha Hall 18.969819 72.807082 Theater
4152 Carmichael Road 18.9722 72.8113 Sophia Bhabha Hall 18.969819 72.807082 Theater
4232 Carmichael Road 18.9722 72.8113 Nehru Auditorium 18.988726 72.814814 Theater
4342 Churchgate 18.93 72.82 Tata Theatre 18.925063 72.819958 Theater
4357 Churchgate 18.93 72.82 Jamshed Bhabha Theatre 18.925134 72.819730 Theater
4386 Churchgate 18.93 72.82 INOX 18.926465 72.822470 Theater
4397 Churchgate 18.93 72.82 Experimental Theatre 18.926086 72.820249 Theater
4440 Cotton Green 18.986209 72.844076 High Street Phoenix 18.994967 72.825032 Shopping Mall
4447 Cotton Green 18.986209 72.844076 Palladium 18.994317 72.824398 Shopping Mall
4541 Cuffe Parade 18.91 72.81 Tata Theatre 18.925063 72.819958 Theater
4554 Cuffe Parade 18.91 72.81 Jamshed Bhabha Theatre 18.925134 72.819730 Theater
4571 Cuffe Parade 18.91 72.81 INOX 18.926465 72.822470 Theater
4573 Cuffe Parade 18.91 72.81 Experimental Theatre 18.926086 72.820249 Theater
4579 Cuffe Parade 18.91 72.81 Maker Arcade 18.916494 72.817852 Shopping Mall
4620 Cumbala Hill 18.965833 72.805833 Sophia Bhabha Hall 18.969819 72.807082 Theater
4701 Currey Road 18.994 72.833 High Street Phoenix 18.994967 72.825032 Shopping Mall
4709 Currey Road 18.994 72.833 Palladium 18.994317 72.824398 Shopping Mall
4763 Currey Road 18.994 72.833 Matterden Centre 19.006067 72.830822 Theater
4880 Dhobitalao 18.9433 72.8286 Tata Theatre 18.925063 72.819958 Theater
4978 Kala Ghoda 18.9307 72.8331 Tata Theatre 18.925063 72.819958 Theater
4999 Kala Ghoda 18.9307 72.8331 Jamshed Bhabha Theatre 18.925134 72.819730 Theater
5008 Kala Ghoda 18.9307 72.8331 INOX 18.926465 72.822470 Theater
5040 Kemps Corner 18.9629 72.8054 Sophia Bhabha Hall 18.969819 72.807082 Theater
5109 Lower Parel 18.995278 72.83 High Street Phoenix 18.994967 72.825032 Shopping Mall
5112 Lower Parel 18.995278 72.83 Palladium 18.994317 72.824398 Shopping Mall
5172 Lower Parel 18.995278 72.83 Matterden Centre 19.006067 72.830822 Theater
5236 Mahalaxmi 18.983333 72.8 Sophia Bhabha Hall 18.969819 72.807082 Theater
5316 Mahim 19.035 72.84 Citylight Theatre 19.030302 72.841627 Theater
5349 Mahim 19.035 72.84 Shivaji Mandir 19.022554 72.842050 Theater
5370 Mahim 19.035 72.84 Le Rêve (Globus Cinema) 19.056014 72.833951 Theater
5492 Marine Drive 18.944 72.823 Tata Theatre 18.925063 72.819958 Theater
5601 Marine Lines 18.9447 72.8244 Tata Theatre 18.925063 72.819958 Theater
5678 Mumbai Central 18.9697 72.8194 Sophia Bhabha Hall 18.969819 72.807082 Theater
5739 Nariman Point 18.926 72.823 Tata Theatre 18.925063 72.819958 Theater
5749 Nariman Point 18.926 72.823 Jamshed Bhabha Theatre 18.925134 72.819730 Theater
5775 Nariman Point 18.926 72.823 INOX 18.926465 72.822470 Theater
5810 Nariman Point 18.926 72.823 Experimental Theatre 18.926086 72.820249 Theater
5863 Prabhadevi 19.0166 72.8295 Matterden Centre 19.006067 72.830822 Theater
5872 Prabhadevi 19.0166 72.8295 High Street Phoenix 18.994967 72.825032 Shopping Mall
5899 Prabhadevi 19.0166 72.8295 Shivaji Mandir 19.022554 72.842050 Theater
5927 Prabhadevi 19.0166 72.8295 Citylight Theatre 19.030302 72.841627 Theater
6006 Sion 19.04 72.86 Citylight Theatre 19.030302 72.841627 Theater
6030 Sion 19.04 72.86 Aurora Cinema 19.028134 72.857326 Theater
6105 Worli 19 72.815 High Street Phoenix 18.994967 72.825032 Shopping Mall
6107 Worli 19 72.815 Palladium 18.994317 72.824398 Shopping Mall
6165 Worli 19 72.815 Matterden Centre 19.006067 72.830822 Theater
6243 C.G.S. colony 19.016378 72.856629 Shivaji Mandir 19.022554 72.842050 Theater
6246 C.G.S. colony 19.016378 72.856629 Big cinemas 19.010945 72.855734 Theater
6266 C.G.S. colony 19.016378 72.856629 Citylight Theatre 19.030302 72.841627 Theater
6275 C.G.S. colony 19.016378 72.856629 Aurora Cinema 19.028134 72.857326 Theater
6284 C.G.S. colony 19.016378 72.856629 Iifa 19.027471 72.853725 Shopping Mall
6308 Dagdi Chawl 18.977129 72.829131 High Street Phoenix 18.994967 72.825032 Shopping Mall
6312 Dagdi Chawl 18.977129 72.829131 Palladium 18.994317 72.824398 Shopping Mall
6390 Dagdi Chawl 18.977129 72.829131 Sophia Bhabha Hall 18.969819 72.807082 Theater
6406 Navy Nagar 18.9012 72.8101 Maker Arcade 18.916494 72.817852 Shopping Mall
6767 Chor Bazaar 18.960321 72.827176 Liberty cinema 18.941652 72.827389 Theater
6802 Matunga 19.01798 72.844763 Shivaji Mandir 19.022554 72.842050 Theater
6833 Matunga 19.01798 72.844763 Matterden Centre 19.006067 72.830822 Theater
6852 Matunga 19.01798 72.844763 Citylight Theatre 19.030302 72.841627 Theater
6874 Parel 18.99 72.84 High Street Phoenix 18.994967 72.825032 Shopping Mall
6881 Parel 18.99 72.84 Palladium 18.994317 72.824398 Shopping Mall
6935 Parel 18.99 72.84 Matterden Centre 19.006067 72.830822 Theater
7008 Gowalia Tank 18.96245 72.809703 Sophia Bhabha Hall 18.969819 72.807082 Theater
7228 Dharavi 19.040208 72.85085 Citylight Theatre 19.030302 72.841627 Theater
7242 Dharavi 19.040208 72.85085 Shivaji Mandir 19.022554 72.842050 Theater
7244 Dharavi 19.040208 72.85085 Le Rêve (Globus Cinema) 19.056014 72.833951 Theater
7274 Thane 19.2 72.97 Viviana 19.208302 72.971991 Shopping Mall
7277 Thane 19.2 72.97 Korum Mall 19.202400 72.965802 Shopping Mall
7286 Thane 19.2 72.97 Gadkari Rangayatan 19.194063 72.973839 Theater
7370 Thane 19.2 72.97 High Street Mall 19.217357 72.980912 Shopping Mall
In [57]:
#3. Analyze Each Neighborhood
# one hot encoding
Mumbai_onehot = pd.get_dummies(Mumbai_venues_2[['Venue Category']], prefix="", prefix_sep="")
Mumbai_onehot
Out[57]:
Shopping Mall Theater
28 0 1
229 0 1
255 0 1
330 0 1
352 0 1
423 0 1
749 0 1
812 0 1
932 0 1
1046 0 1
1257 0 1
1290 0 1
1336 0 1
1378 0 1
1395 0 1
1427 1 0
1437 1 0
1629 0 1
1771 0 1
1803 1 0
1862 1 0
1930 1 0
1997 0 1
2004 1 0
2032 1 0
2049 1 0
2229 1 0
2300 1 0
2308 1 0
2332 1 0
2527 0 1
2627 0 1
2708 1 0
2733 1 0
2826 1 0
2833 0 1
2842 1 0
2846 1 0
2947 0 1
2951 1 0
2961 1 0
3049 1 0
3083 1 0
3096 0 1
3124 1 0
3162 1 0
3278 1 0
3410 1 0
3413 1 0
3428 0 1
3434 1 0
3514 0 1
3537 1 0
3595 0 1
3677 0 1
3747 1 0
3752 1 0
3833 0 1
3849 0 1
4051 0 1
4152 0 1
4232 0 1
4342 0 1
4357 0 1
4386 0 1
4397 0 1
4440 1 0
4447 1 0
4541 0 1
4554 0 1
4571 0 1
4573 0 1
4579 1 0
4620 0 1
4701 1 0
4709 1 0
4763 0 1
4880 0 1
4978 0 1
4999 0 1
5008 0 1
5040 0 1
5109 1 0
5112 1 0
5172 0 1
5236 0 1
5316 0 1
5349 0 1
5370 0 1
5492 0 1
5601 0 1
5678 0 1
5739 0 1
5749 0 1
5775 0 1
5810 0 1
5863 0 1
5872 1 0
5899 0 1
5927 0 1
6006 0 1
6030 0 1
6105 1 0
6107 1 0
6165 0 1
6243 0 1
6246 0 1
6266 0 1
6275 0 1
6284 1 0
6308 1 0
6312 1 0
6390 0 1
6406 1 0
6767 0 1
6802 0 1
6833 0 1
6852 0 1
6874 1 0
6881 1 0
6935 0 1
7008 0 1
7228 0 1
7242 0 1
7244 0 1
7274 1 0
7277 1 0
7286 0 1
7370 1 0
In [58]:
# add neighborhood column back to dataframe
Mumbai_onehot['Neighborhood'] = Mumbai_venues_2['Neighborhood'] 
In [59]:
# move neighborhood column to the first column
fixed_columns = [Mumbai_onehot.columns[-1]] + list(Mumbai_onehot.columns[:-1])
Mumbai_onehot = Mumbai_onehot[fixed_columns]
Mumbai_onehot.head()
Out[59]:
Neighborhood Shopping Mall Theater
28 Amboli 0 1
229 D.N. Nagar 0 1
255 D.N. Nagar 0 1
330 Four Bungalows 0 1
352 Four Bungalows 0 1
In [60]:
Mumbai_onehot.shape
Out[60]:
(129, 3)
In [61]:
#Next, let's group rows by neighborhood and by taking the mean of the frequency of occurrence of each category
Mumbai_grouped_1 = Mumbai_onehot.groupby('Neighborhood').sum().reset_index()
Mumbai_grouped_2 = Mumbai_onehot.groupby('Neighborhood').mean().reset_index()
Mumbai_grouped= Mumbai_grouped_1.merge(Mumbai_grouped_2,how='inner',left_on=['Neighborhood'],right_on=['Neighborhood'])
Mumbai_grouped
Mumbai_grouped.shape
Out[61]:
(64, 5)
In [62]:
Mumbai_grouped.head()
Out[62]:
Neighborhood Shopping Mall_x Theater_x Shopping Mall_y Theater_y
0 Agripada 2 1 0.666667 0.333333
1 Altamount Road 0 1 0.000000 1.000000
2 Amboli 0 1 0.000000 1.000000
3 Amrut Nagar 2 0 1.000000 0.000000
4 Asalfa 2 1 0.666667 0.333333
In [63]:
#4. Cluster Neighborhoods findout best K
Mumbai_grouped_clustering = Mumbai_grouped_2.drop('Neighborhood', 1)

sil = []
kmax = 10

# dissimilarity would not be defined for a single cluster, thus, minimum number of clusters should be 2
for k in range(2, kmax):
    kmeans = KMeans(n_clusters=k, random_state=1).fit(Mumbai_grouped_clustering)
    labels = kmeans.labels_
    sil.append(silhouette_score(Mumbai_grouped_clustering, labels, metric = 'euclidean'))
In [64]:
sil
Out[64]:
[0.8746790609454447,
 0.9278923830070563,
 0.9647569403395169,
 0.9811631761149555,
 0.9691406059845273,
 0.9687499756338532,
 0.9687499756338532,
 0.9687499756338532]
In [65]:
# Plot the elbow
k= range(2,10)
plt.plot(k, sil, 'bx-')
plt.xlabel('k')
plt.ylabel('sil')
plt.title('The Silhouette Method showing the optimal k')
plt.show()
In [66]:
# The best number of clusters with min of cluster value is 6 from above chart
# set number of clusters
kclusters = 5

# run k-means clustering
kmeans = KMeans(n_clusters=kclusters, random_state=1).fit(Mumbai_grouped_clustering)

# check cluster labels generated for each row in the dataframe
kmeans.labels_[0:10] 
Out[66]:
array([2, 0, 0, 1, 2, 0, 1, 1, 0, 3])
In [67]:
#Mumbai_grouped_clustering
#Let's create a new dataframe that includes the cluster as well as the top 10 venues for each neighborhood.
# add clustering labels
Mumbai_grouped.insert(0,'Cluster Labels', kmeans.labels_)
Mumbai_merged = MumbaiLatLan

# merge manhattan_grouped with manhattan_data to add latitude/longitude for each neighborhood
Mumbai_merged = Mumbai_merged.merge(Mumbai_grouped,how='inner',left_on=['Area'],right_on=['Neighborhood'])


Mumbai_merged.head() # check the last columns!
Out[67]:
Area Location Latitude Longitude Cluster Labels Neighborhood Shopping Mall_x Theater_x Shopping Mall_y Theater_y
0 Amboli Andheri,Western Suburbs 19.1293 72.8434 0 Amboli 0 1 0.0 1.0
1 D.N. Nagar Andheri,Western Suburbs 19.124085 72.831373 0 D.N. Nagar 0 2 0.0 1.0
2 Four Bungalows Andheri,Western Suburbs 19.124714 72.82721 0 Four Bungalows 0 2 0.0 1.0
3 Lokhandwala Andheri,Western Suburbs 19.130815 72.82927 0 Lokhandwala 0 1 0.0 1.0
4 Seven Bungalows Andheri,Western Suburbs 19.129052 72.817018 0 Seven Bungalows 0 1 0.0 1.0
In [69]:
#updaating lables for each cluster
Mumbai_merged['Labels'] = Mumbai_merged['Cluster Labels'].map({0:'Only Theater',1:'Only Shopping Mall'
                                ,2:'66% Shopping Mall/33% Theater',3:'33% Shopping Mall/66% Theater'
                                ,4:'75% Shopping Mall/25% Theater'})
Mumbai_merged
Out[69]:
Area Location Latitude Longitude Cluster Labels Neighborhood Shopping Mall_x Theater_x Shopping Mall_y Theater_y Labels
0 Amboli Andheri,Western Suburbs 19.1293 72.8434 0 Amboli 0 1 0.000000 1.000000 Only Theater
1 D.N. Nagar Andheri,Western Suburbs 19.124085 72.831373 0 D.N. Nagar 0 2 0.000000 1.000000 Only Theater
2 Four Bungalows Andheri,Western Suburbs 19.124714 72.82721 0 Four Bungalows 0 2 0.000000 1.000000 Only Theater
3 Lokhandwala Andheri,Western Suburbs 19.130815 72.82927 0 Lokhandwala 0 1 0.000000 1.000000 Only Theater
4 Seven Bungalows Andheri,Western Suburbs 19.129052 72.817018 0 Seven Bungalows 0 1 0.000000 1.000000 Only Theater
5 Versova Andheri,Western Suburbs 19.12 72.82 0 Versova 0 1 0.000000 1.000000 Only Theater
6 Mira Road Mira-Bhayandar,Western Suburbs 19.284167 72.871111 0 Mira Road 0 1 0.000000 1.000000 Only Theater
7 Bandstand Promenade Bandra,Western Suburbs 19.042718 72.819132 0 Bandstand Promenade 0 1 0.000000 1.000000 Only Theater
8 I.C. Colony Borivali (West),Western Suburbs 19.247039 72.84983 0 I.C. Colony 0 2 0.000000 1.000000 Only Theater
9 Dahisa Western Suburbs 19.250069 72.859347 0 Dahisa 0 3 0.000000 1.000000 Only Theater
10 Bangur Nagar Goregaon,Western Suburbs 19.167362 72.832252 1 Bangur Nagar 2 0 1.000000 0.000000 Only Shopping Mall
11 Juhu Western Suburbs 19.1 72.83 0 Juhu 0 1 0.000000 1.000000 Only Theater
12 Charkop Kandivali West,Western Suburbs 19.216182 72.830575 0 Charkop 0 1 0.000000 1.000000 Only Theater
13 Poisar Kandivali West,Western Suburbs 19.204511 72.837639 1 Poisar 2 0 1.000000 0.000000 Only Shopping Mall
14 Mahavir Nagar Kandivali West,Western Suburbs 19.211319 72.842737 1 Mahavir Nagar 1 0 1.000000 0.000000 Only Shopping Mall
15 Thakur village Kandivali East,Western Suburbs 19.210206 72.87298 4 Thakur village 3 1 0.750000 0.250000 75% Shopping Mall/25% Theater
16 Dindoshi Malad,Western Suburbs 19.176382 72.864891 1 Dindoshi 1 0 1.000000 0.000000 Only Shopping Mall
17 Sunder Nagar Malad,Western Suburbs 19.175 72.842 1 Sunder Nagar 3 0 1.000000 0.000000 Only Shopping Mall
18 Irla Vile Parle,Western Suburbs 19.108056 72.838056 0 Irla 0 1 0.000000 1.000000 Only Theater
19 Vile Parle Western Suburbs 19.1 72.83 0 Vile Parle 0 1 0.000000 1.000000 Only Theater
20 Bhandup Eastern Suburbs 19.14 72.93 1 Bhandup 1 0 1.000000 0.000000 Only Shopping Mall
21 Amrut Nagar Ghatkopar,Eastern Suburbs 19.102077 72.912835 1 Amrut Nagar 2 0 1.000000 0.000000 Only Shopping Mall
22 Asalfa Ghatkopar,Eastern Suburbs 19.091 72.901 2 Asalfa 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
23 Pant Nagar Ghatkopar,Eastern Suburbs 19.08 72.91 2 Pant Nagar 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
24 Kanjurmarg Eastern Suburbs 19.13 72.94 1 Kanjurmarg 1 0 1.000000 0.000000 Only Shopping Mall
25 Nahur Mulund,Eastern Suburbs 19.157 72.941 2 Nahur 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
26 Chandivali Powai,Eastern Suburbs 19.11 72.9 1 Chandivali 1 0 1.000000 0.000000 Only Shopping Mall
27 Hiranandani Gardens Powai,Eastern Suburbs 19.118986 72.911767 1 Hiranandani Gardens 1 0 1.000000 0.000000 Only Shopping Mall
28 Indian Institute of Technology Bombay campus Powai,Eastern Suburbs 19.133636 72.915358 1 Indian Institute of Technology Bombay campus 2 0 1.000000 0.000000 Only Shopping Mall
29 Vidyavihar Eastern Suburbs 19.08 72.896 3 Vidyavihar 1 2 0.333333 0.666667 33% Shopping Mall/66% Theater
30 Vikhroli Eastern Suburbs 19.11 72.94 1 Vikhroli 1 0 1.000000 0.000000 Only Shopping Mall
31 Chembur Harbour Suburbs 19.051 72.894 0 Chembur 0 1 0.000000 1.000000 Only Theater
32 Deonar Govandi,Harbour Suburbs 19.05 72.89 0 Deonar 0 1 0.000000 1.000000 Only Theater
33 Agripada South Mumbai 18.9777 72.8273 2 Agripada 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
34 Altamount Road South Mumbai 18.9681 72.8095 0 Altamount Road 0 1 0.000000 1.000000 Only Theater
35 Breach Candy South Mumbai 18.967 72.805 0 Breach Candy 0 1 0.000000 1.000000 Only Theater
36 Carmichael Road South Mumbai 18.9722 72.8113 0 Carmichael Road 0 2 0.000000 1.000000 Only Theater
37 Churchgate South Mumbai 18.93 72.82 0 Churchgate 0 4 0.000000 1.000000 Only Theater
38 Cotton Green South Mumbai 18.986209 72.844076 1 Cotton Green 2 0 1.000000 0.000000 Only Shopping Mall
39 Cuffe Parade South Mumbai 18.91 72.81 3 Cuffe Parade 1 4 0.200000 0.800000 33% Shopping Mall/66% Theater
40 Cumbala Hill South Mumbai 18.965833 72.805833 0 Cumbala Hill 0 1 0.000000 1.000000 Only Theater
41 Currey Road South Mumbai 18.994 72.833 2 Currey Road 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
42 Dhobitalao South Mumbai 18.9433 72.8286 0 Dhobitalao 0 1 0.000000 1.000000 Only Theater
43 Kala Ghoda South Mumbai 18.9307 72.8331 0 Kala Ghoda 0 3 0.000000 1.000000 Only Theater
44 Kemps Corner South Mumbai 18.9629 72.8054 0 Kemps Corner 0 1 0.000000 1.000000 Only Theater
45 Lower Parel South Mumbai 18.995278 72.83 2 Lower Parel 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
46 Mahalaxmi South Mumbai 18.983333 72.8 0 Mahalaxmi 0 1 0.000000 1.000000 Only Theater
47 Mahim South Mumbai 19.035 72.84 0 Mahim 0 3 0.000000 1.000000 Only Theater
48 Marine Drive South Mumbai 18.944 72.823 0 Marine Drive 0 1 0.000000 1.000000 Only Theater
49 Marine Lines South Mumbai 18.9447 72.8244 0 Marine Lines 0 1 0.000000 1.000000 Only Theater
50 Mumbai Central South Mumbai 18.9697 72.8194 0 Mumbai Central 0 1 0.000000 1.000000 Only Theater
51 Nariman Point South Mumbai 18.926 72.823 0 Nariman Point 0 4 0.000000 1.000000 Only Theater
52 Prabhadevi South Mumbai 19.0166 72.8295 3 Prabhadevi 1 3 0.250000 0.750000 33% Shopping Mall/66% Theater
53 Sion South Mumbai 19.04 72.86 0 Sion 0 2 0.000000 1.000000 Only Theater
54 Worli South Mumbai 19 72.815 2 Worli 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
55 C.G.S. colony Antop Hill,South Mumbai 19.016378 72.856629 3 C.G.S. colony 1 4 0.200000 0.800000 33% Shopping Mall/66% Theater
56 Dagdi Chawl Byculla,South Mumbai 18.977129 72.829131 2 Dagdi Chawl 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
57 Navy Nagar Colaba,South Mumbai 18.9012 72.8101 1 Navy Nagar 1 0 1.000000 0.000000 Only Shopping Mall
58 Chor Bazaar Kamathipura,South Mumbai 18.960321 72.827176 0 Chor Bazaar 0 1 0.000000 1.000000 Only Theater
59 Matunga South Mumbai 19.01798 72.844763 0 Matunga 0 3 0.000000 1.000000 Only Theater
60 Parel South Mumbai 18.99 72.84 2 Parel 2 1 0.666667 0.333333 66% Shopping Mall/33% Theater
61 Gowalia Tank Tardeo,South Mumbai 18.96245 72.809703 0 Gowalia Tank 0 1 0.000000 1.000000 Only Theater
62 Dharavi Mumbai 19.040208 72.85085 0 Dharavi 0 3 0.000000 1.000000 Only Theater
63 Thane Mumbai 19.2 72.97 4 Thane 3 1 0.750000 0.250000 75% Shopping Mall/25% Theater
In [71]:
#Finally, let's visualize the resulting clusters

# create map
map_clusters = folium.Map(location=[latitude, longitude], zoom_start=11)

# set color scheme for the clusters
x = np.arange(kclusters)
ys = [i + x + (i*x)**2 for i in range(kclusters)]
colors_array = cm.rainbow(np.linspace(0, 1, len(ys)))
rainbow = [colors.rgb2hex(i) for i in colors_array]

# add markers to the map
markers_colors = []
for lat, lon, poi, cluster,Labels, X1,X2 in zip(Mumbai_merged['Latitude'], Mumbai_merged['Longitude'], Mumbai_merged['Neighborhood'], Mumbai_merged['Cluster Labels'],Mumbai_merged['Labels'], Mumbai_merged['Shopping Mall_x'], Mumbai_merged['Theater_x']):
    label = folium.Popup(str(poi) + ' Area' +' has-'+ str(Labels)+'; Shopping Mall-'+str(X1)+' Theater-'+str(X2), parse_html=True)
    folium.CircleMarker(
        [lat, lon],
        radius=5,
        popup=label,
        color=rainbow[cluster-1],
        fill=True,
        fill_color=rainbow[cluster-1],
        fill_opacity=0.7).add_to(map_clusters)
       
map_clusters
Out[71]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [72]:
# get mumbai geojson data
mumbai_geo = r'https://raw.githubusercontent.com/datameet/PincodeBoundary/master/Mumbai/boundary.geojson' # geojson file
In [73]:
# get Mumbai area wise density information
Mumbai_den = pd.read_csv(r'C:\Users\Puneet\Desktop\Data_Casptone_project\Mumbai_density.csv')

Mumbai_den.head()
Out[73]:
Pincode Area Density_Square_Kilometer
0 400001 MUMBAI GPO 56253.20
1 400002 kalbadevi 56253.20
2 400003 Mandvi 56253.20
3 400004 girgaon 112734.44
4 400005 COLABA POST OFFICE 16867.76
In [74]:
# generate choropleth map to visualiaze the populatin density
map_mumbai = folium.Map(location=[latitude, longitude], zoom_start=11)

map_mumbai.choropleth(
    geo_data=mumbai_geo,
    data=Mumbai_den,
    columns=['Area', 'Density_Square_Kilometer'],
    key_on='feature.properties.name',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Mumbai Population Density per KM'
)

# display map
map_mumbai
C:\ProgramData\Anaconda3\lib\site-packages\folium\folium.py:413: FutureWarning: The choropleth  method has been deprecated. Instead use the new Choropleth class, which has the same arguments. See the example notebook 'GeoJSON_and_choropleth' for how to do this.
  FutureWarning
Out[74]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [76]:
#Finally, let's visualize the resulting clusters and Mumbai city population density in a single map

# create map
map_clusters = map_mumbai

# set color scheme for the clusters
x = np.arange(kclusters)
ys = [i + x + (i*x)**2 for i in range(kclusters)]
colors_array = cm.rainbow(np.linspace(0, 1, len(ys)))
rainbow = [colors.rgb2hex(i) for i in colors_array]

# add markers to the map
markers_colors = []
for lat, lon, poi, cluster,Labels, X1,X2 in zip(Mumbai_merged['Latitude'], Mumbai_merged['Longitude'], Mumbai_merged['Neighborhood'], Mumbai_merged['Cluster Labels'],Mumbai_merged['Labels'], Mumbai_merged['Shopping Mall_x'], Mumbai_merged['Theater_x']):
    label = folium.Popup(str(poi) + ' Area' +' has-'+ str(Labels)+'; Shopping Mall-'+str(X1)+' Theater-'+str(X2), parse_html=True)
    folium.CircleMarker(
        [lat, lon],
        radius=5,
        popup=label,
        color=rainbow[cluster-1],
        fill=True,
        fill_color=rainbow[cluster-1],
        fill_opacity=0.7).add_to(map_clusters)
       
map_clusters
Out[76]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]:
#The End